﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using 数据验证;

namespace 热更验证
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        int index = 0; //项目索引
        Type types = typeof(Riyue); //默认项目类型日月
        string oldPath = Directory.GetCurrentDirectory() + @"\Xml.xml"; //项目地址库
        MyPath myPath;
        MyLoad myLoad;
        Form2 form2;
        XmlDocument xmlDoc = null;

        /// <summary>
        /// 1.选择查询项目
        /// </summary>
        private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            //控件内容清理
            X_listView.Clear();
            ab_listView.Clear();
            XPath_textBox.Clear();
            info_richTextBox.Clear();

            //设置所有开关关闭
            Step1(0);
            Step2(0);
            Step3(0);
            Step4(0);

            //各文档初始化
            xmlDoc = null;

            index = comboBox.SelectedIndex;

            myPath = null;
            myLoad = null;

            switch (index)
            {
                case 0:
                    types = typeof(Riyue);
                    InfoText("********日月********");
                    break;

                case 1:
                    types = typeof(Juedou);
                    InfoText("********决斗********");
                    break;

                case 2:
                    types = typeof(Xinmiaomiao);
                    InfoText("********新喵喵********");
                    break;

                case 3:
                    types = typeof(Xinnixi);
                    InfoText("********新逆袭********");
                    break;

                case 4:
                    types = typeof(Xinshidai);
                    InfoText("********新世代********");
                    break;

                case 5:
                    types = typeof(RiyueTY);
                    InfoText("********日月通用********");
                    break;
            }
            
            //检查地址库文件是否存在
            if (File.Exists(oldPath))
            {
                //获取历史地址信息
                xmlDoc = new XmlDocument();

                try
                {
                    xmlDoc.Load(oldPath);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.StackTrace);
                }
                
                XmlElement root = xmlDoc.DocumentElement;
                XmlNodeList nodeList = root.ChildNodes;

                foreach (XmlNode item in nodeList)
                {
                    string id = item.Attributes["ID"].Value;
                    if (id == index.ToString())
                    {
                        string path = item.ChildNodes.Item(0).InnerText;
                        if (string.IsNullOrEmpty(path))
                        {
                            InfoText("*无历史地址信息*");
                        }
                        else
                        {
                            if (!Directory.Exists(path)) InfoText("*历史地址信息无效,请选择有效路径*");
                            else XPath_textBox.Text = path;
                        }
                    }
                }
                xmlDoc.Save(oldPath);
            }
            else
            {
                Step1(3);
                //创建地址库文件
                using (File.Create(oldPath)) InfoText("*新建地址库文件成功*");
                xmlDoc = new XmlDocument();
                XmlDeclaration declaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8",null);
                XmlElement root = xmlDoc.CreateElement("list");
                xmlDoc.AppendChild(declaration);
                xmlDoc.AppendChild(root);
                for (int i = 0; i < comboBox.Items.Count; i++)
                {
                    XmlElement createElement = xmlDoc.CreateElement("id");
                    XmlElement path = xmlDoc.CreateElement("path");
                    path.InnerText = "";
                    createElement.SetAttribute("ID", i.ToString());
                    createElement.AppendChild(path);
                    root.AppendChild(createElement);
                }
                xmlDoc.Save(oldPath);
            }
            Step1(3);
        }

        /// <summary>
        /// 2.获取XML文档地址
        /// </summary>
        private void XPath_button_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK) XPath_textBox.Text = folderBrowserDialog.SelectedPath;
        }

        /// <summary>
        /// 3.检查文档路径是否有效
        /// </summary>
        private void XPath_textBox_TextChanged(object sender, EventArgs e)
        {
            string path = XPath_textBox.Text;
            if (!String.IsNullOrEmpty(path))
            {
                if (Directory.Exists(path))
                {
                    myPath = new MyPath(path,index);
                    if (!myPath.CheckPath()) 
                    {
                        InfoText(myPath.message);
                        MessageBox.Show("缺少核心文件,请检查当前路径是否有效！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        check_button.Enabled = false;
                        return;
                    }

                    myLoad = new MyLoad(myPath);

                    try
                    {
                        if (!myLoad.LoadAllXml())
                        {
                            InfoText(myLoad.Message);
                        }

                        //if (!myLoad.LoadChest())
                        //{
                        //    InfoText(myLoad.TempMessage);
                        //}

                        InfoText("-----表格读取完毕-----");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.StackTrace);
                    }
                    
                    ChangePath();

                    Step1(1);
                    Step2(3);
                    Step3(1);
                    Step4(1);
                }
                else
                {
                    MessageBox.Show("路径无效", "警告", MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
            }
        }

        /// <summary>
        /// 4.查询精灵
        /// </summary>
        private void check_button_Click(object sender, EventArgs e)
        {
            string petID = Name_textBox.Text;
            petID = petID.Trim();
            string petID2 = "";
            int tempID;
            bool key = true; //false表示petID为文字,true为数字

            if (String.IsNullOrEmpty(petID)) //判断输入是否为空
            {
                MessageBox.Show("0.输入不能为空,请重新输入", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!Int32.TryParse(petID,out tempID)) //判断输入是否非数字
            {
                if (myLoad.petNameHK.ContainsKey(petID))
                {
                    petID2 = myLoad.petNameHK.GetTvalue(petID);
                    petID2 = petID2.Trim();
                    key = false; 
                }
                else
                {
                    MessageBox.Show("1.精灵名字 错误,请重新输入", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

            }
            if (index == 3)
            {
                object obj ;
                string nextID = "";
                string prePetId = "";
                string petIDTemp = "";
                SortedList<string, object> petlist = new SortedList<string, object>();

                switch (key)
                {
                    case true: //为数字型字符串时
                        if (myLoad.psIDTable.ContainsKey(petID))
                        {
                            petIDTemp = petID;
                            nextID = myLoad.petSeriseTable[petID].ToString();
                            prePetId = (Int32.Parse(petID) - 1).ToString();
                            obj = myLoad.psIDTable[petID];
                            petlist.Add(petID, obj);
                        }
                        else
                        {
                            MessageBox.Show("2.精灵ID 错误,请重新输入", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        break;
                    case false: //为文字型字符串时
                        if (myLoad.psIDTable.ContainsKey(petID2))
                        {
                            petIDTemp = petID2;
                            nextID = myLoad.petSeriseTable[petID2].ToString();
                            prePetId = (Int32.Parse(petID2) - 1).ToString();
                            obj = myLoad.psIDTable[petID2];
                            petlist.Add(petID2, obj);
                        }
                        else
                        {
                            MessageBox.Show("3.精灵ID 错误,请重新输入", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        break;
                }

                //前置精灵ID
                if (myLoad.petSeriseTable.ContainsKey(prePetId))
                {
                    while (myLoad.petSeriseTable[prePetId].ToString() == petIDTemp)
                    {
                        petIDTemp = prePetId;
                        prePetId = (Int32.Parse(petIDTemp) - 1).ToString();
                        obj = myLoad.psIDTable[petIDTemp];
                        petlist.Add(petIDTemp, obj);
                    }
                }

                //进化ID
                string last = default;
                if (nextID == "0")
                {
                    obj = myLoad.psIDTable[petIDTemp];
                    last = myLoad.petTypeDic["MegaPetId"].GetValue(obj).ToString();
                    while (myLoad.psIDTable.ContainsKey(last))
                    {
                        obj = myLoad.psIDTable[last];
                        petlist.Add(last, obj);
                        last = myLoad.petTypeDic["MegaPetId"].GetValue(obj).ToString();
                    }
                }
                else
                {
                    while (myLoad.petSeriseTable.ContainsKey(nextID))
                    {
                        petIDTemp = nextID;
                        nextID = myLoad.petSeriseTable[petIDTemp].ToString();
                        obj = myLoad.psIDTable[petIDTemp];
                        petlist.Add(petIDTemp, obj);
                        if (nextID == "0")
                        {
                            last = myLoad.petTypeDic["MegaPetId"].GetValue(obj).ToString();
                            while (myLoad.psIDTable.ContainsKey(last))
                            {
                                obj = myLoad.psIDTable[last];
                                petlist.Add(last, obj);
                                last = myLoad.petTypeDic["MegaPetId"].GetValue(obj).ToString();
                            }
                        }
                    }
                }
                for (int i = 0; i < petlist.Values.Count; i++) SetListViewItem(petlist.Values[i]);
                SetListViewItem2();
            }
            else
            {
                string seriseID = "";
                switch (key)
                {
                    case true:
                        if (myLoad.psIDTable.ContainsKey(petID))
                        {
                            seriseID = myLoad.psIDTable[petID].ToString();
                        }
                        else
                        {
                            MessageBox.Show("精灵ID 错误,请重新输入", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        break;
                    case false:
                        if (myLoad.psIDTable.ContainsKey(petID2))
                        {
                            seriseID = myLoad.psIDTable[petID2].ToString();
                        }
                        else
                        {
                            MessageBox.Show("精灵ID 错误,请重新输入", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        break;
                }
                List<object> objlist = myLoad.petSeriseTable[seriseID] as List<object>;
                for (int i = 0; i < objlist.Count; i++) SetListViewItem(objlist[i]);
                //foreach (var item in objlist) SetListViewItem(item);
                SetListViewItem2();
            }

            void SetListViewItem2()
            {
                this.X_listView.BeginUpdate();
                this.ab_listView.BeginUpdate();

                ListViewItem lvi = new ListViewItem();
                ListViewItem lvi2 = new ListViewItem();

                for (int i = 0; i < X_listView.Columns.Count; i++)
                {
                    lvi.SubItems.Add("");
                }

                for (int i = 0; i < ab_listView.Columns.Count; i++)
                {
                    lvi2.SubItems.Add("");
                }

                //为数据列表添加一行数据
                this.X_listView.Items.Add(lvi);
                this.ab_listView.Items.Add(lvi2);

                //结束数据处理,UI界面一次性绘制
                this.X_listView.EndUpdate();
                this.ab_listView.EndUpdate();
            }

            InfoText("~查询完毕~");
        }

        /// <summary>
        /// 5.查询单个XML文档是否存在重复ID
        /// </summary>
        private void XmlXCheck_button_Click(object sender, EventArgs e)
        {
            string name = XmlName_textBox.Text;
            string index = XmlIndex_textBox.Text;
            string patx = XPath_textBox.Text;
            string XmlPath = patx + @"\" + name + @".xml";
            int i;

            //检查输入是否有效值
            if (String.IsNullOrEmpty(patx) || String.IsNullOrEmpty(name) || String.IsNullOrEmpty(index))
            {
                MessageBox.Show("输入存在有空值！\n请检查： \n文件路径（XML位置）\n文件名（XML名称无需加后缀）\n索引位置（索引从0开始,第一个字段为0,第二个为1,依次类推） ", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            
            //检查索引是否为有效数字,并返回 int 类型索引 i
            if (!Int32.TryParse(index, out i))
            {
                MessageBox.Show("输入的索引值错误,请输入数字索引", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //检查文件地址是否正确
            if (!File.Exists(XmlPath))
            {
                InfoText2("文件无效,请检查文件名: " + XmlPath);
                MessageBox.Show("文件无效,请检查文件名", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            InfoText2("**************XML重复ID 开始比对**************");
            XmlLoader loader = new XmlLoader(XmlPath, i);
            if (loader.IsRepeate())
            {
                HashSet<string> list = loader.GetRepeate();
                foreach (var item in list) InfoText2(name + " 重复 " + loader.GetKey() + " ID：" + item);
            }
            InfoText2("**************XML重复ID 比对完毕**************");
            MessageBox.Show("校对完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        /// <summary>
        /// 6.验证升星升阶跳转
        /// </summary>
        private void dropLevel_button_Click(object sender, EventArgs e)
        {
            InfoText2("******验证升星升阶跳转 开始检查******");
            HashK<string, string> items_dropLevelList_hashK = new HashK<string, string>();
            HashK<string, string> npcListhashK = new HashK<string, string>();
            HashK<string, StringBuilder> drophashK = new HashK<string, StringBuilder>();
            int count = 20;
            string[] str = new string[count];
            for (int i = 0; i < count; i++)
            {
                string temp;
                if (i < 10) temp = "40000000" + i.ToString();
                else temp = "4000000" + i.ToString();
                str[i] = temp;
            }

            HashSet<string> set = new HashSet<string>(str);
            try
            {
                using (XmlTextReader reader = new XmlTextReader(myPath.itemsPath))
                {
                    reader.WhitespaceHandling = WhitespaceHandling.None;
                    string itemId = "";
                    string dropLevelList = "";
                    while (reader.Read())
                    {
                        reader.ReadToFollowing("itemType");
                        if (reader.ReadString() == "5" & reader.EOF == false)
                        {
                            reader.ReadToFollowing("itemId");
                            itemId = reader.ReadString();
                            reader.ReadToFollowing("dropLevelList");
                            dropLevelList = reader.ReadString();
                            if (dropLevelList != "0")
                            {
                                if (!items_dropLevelList_hashK.ContainsKey(itemId)) items_dropLevelList_hashK.Add(itemId, dropLevelList);
                            }
                        }
                    }
                }

                using (XmlTextReader reader = new XmlTextReader(myPath.npcListPath))
                {
                    reader.WhitespaceHandling = WhitespaceHandling.None;
                    string npcId = "";
                    string dropId = "";
                    while (reader.Read())
                    {
                        reader.ReadToFollowing("npcId");
                        npcId = reader.ReadString();
                        reader.ReadToFollowing("dropId");
                        dropId = reader.ReadString();
                        if (reader.EOF == false & dropId != "0")
                        {
                            if (!npcListhashK.ContainsKey(npcId)) npcListhashK.Add(npcId, dropId);
                            else InfoText2("npcList/npcId 重复：" + npcId);
                        }
                    }
                }

                using (XmlTextReader reader = new XmlTextReader(myPath.dropPath))
                {
                    reader.WhitespaceHandling = WhitespaceHandling.None;
                    string dropId = "";
                    string temp = "";
                    StringBuilder builder = new StringBuilder();
                    while (reader.Read())
                    {
                        reader.ReadToFollowing("dropId");
                        dropId = reader.ReadString();
                        if (reader.EOF == false)
                        {
                            reader.ReadToFollowing("item_1");
                            temp = reader.ReadString();
                            if (temp != "0") builder.Append(temp);

                            reader.ReadToFollowing("item_2");
                            temp = reader.ReadString();
                            if (temp != "0") builder.Append("," + temp);

                            reader.ReadToFollowing("item_3");
                            temp = reader.ReadString();
                            if (temp != "0") builder.Append("," + temp);

                            reader.ReadToFollowing("item_4");
                            temp = reader.ReadString();
                            if (temp != "0") builder.Append("," + temp);

                            reader.ReadToFollowing("item_5");
                            temp = reader.ReadString();
                            if (temp != "0") builder.Append("," + temp);

                            reader.ReadToFollowing("item_6");
                            temp = reader.ReadString();
                            if (temp != "0") builder.Append("," + temp);

                            reader.ReadToFollowing("item_7");
                            temp = reader.ReadString();
                            if (temp != "0") builder.Append("," + temp);

                            reader.ReadToFollowing("item_8");
                            temp = reader.ReadString();
                            if (temp != "0") builder.Append("," + temp);

                            reader.ReadToFollowing("item_9");
                            temp = reader.ReadString();
                            if (temp != "0") builder.Append("," + temp);

                            reader.ReadToFollowing("item_10");
                            temp = reader.ReadString();
                            if (temp != "0") builder.Append("," + temp);

                            if (!drophashK.ContainsKey(dropId))
                            {
                                drophashK.Add(dropId, builder);
                                builder = new StringBuilder();
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.StackTrace);
            }
            

            foreach (string item in items_dropLevelList_hashK.Keys)
            {
                string dropLevelList = items_dropLevelList_hashK.GetTvalue(item);
                string[] dropLevel = dropLevelList.Split(';');
                StringBuilder builder;
                string temp = "";
                for (int i = 0; i < dropLevel.Length; i++)
                {
                    if (!set.Contains(dropLevel[i]))
                    {
                        if (npcListhashK.ContainsKey(dropLevel[i]))
                        {
                            string dropId = npcListhashK.GetTvalue(dropLevel[i]);
                            if (drophashK.ContainsKey(dropId))
                            {
                                builder = drophashK.GetTvalue(dropId);
                                if (!((builder.ToString()).Contains(item)))
                                {
                                    if (temp != item)
                                    {
                                        InfoText2("itemID掉落跳转异常：" + item);
                                        temp = item;
                                    }
                                }
                            }
                            else InfoText2("npcList/dropId 不在drop表中：" + dropId);
                        }
                        else InfoText2("items/dropLevelList 不在npcList表中：" + dropLevelList);
                    }
                }
            }
            MessageBox.Show("检查完毕");
            InfoText2("******验证升星升阶跳转 检查完毕******");
        }

        /// <summary>
        /// 7.查询宝箱内容
        /// </summary>
        private void chest_button_Click(object sender, EventArgs e)
        {
            if (chest_comboBox.SelectedIndex == -1)
            {
                MessageBox.Show("请先选择查询类型！");
                return;
            }
            if (chest_comboBox.SelectedIndex == 0)
            {
                this.table2_listView.BeginUpdate();
                foreach (Chest item in myLoad.chestTable.Values) ShowListView(item);
                this.table2_listView.EndUpdate();
            }
            else
            {
                string chest = chest_textBox.Text.Trim();
                if (myLoad.chestTable.ContainsKey(chest))
                {
                    Chest item = (Chest)myLoad.chestTable[chest];
                    this.table2_listView.BeginUpdate();
                    ShowListView(item);
                    this.table2_listView.EndUpdate();
                }
                else
                {
                    MessageBox.Show("宝箱ID错误：" + chest_textBox.Text);
                }
            }
        }

        /// <summary>
        /// 8.提取XML核心文件
        /// </summary>
        private void getxml_button_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(myPath.xPath)) return;
            string current;
            List<string> list;
            switch (index)
            {
                case 0:
                    current = Directory.GetCurrentDirectory() + @"\日月";
                    list = new List<string>(myPath.SetRiyuePath());
                    GetXml();
                    InfoText("********提取日月核心文件********");
                    break;

                case 1:
                    current = Directory.GetCurrentDirectory() + @"\决斗";
                    list = new List<string>(myPath.SetJuedouPath());
                    GetXml();
                    InfoText("********提取决斗核心文件********");
                    break;

                case 2:
                    current = Directory.GetCurrentDirectory() + @"\新喵喵";
                    list = new List<string>(myPath.SetXinmiaomiaoPath());
                    GetXml();
                    InfoText("********提取新喵喵核心文件********");
                    break;

                case 3:
                    current = Directory.GetCurrentDirectory() + @"\新逆袭";
                    list = new List<string>(myPath.SetXinnixiPath());
                    GetXml();
                    InfoText("********提取新逆袭核心文件********");
                    break;

                case 4:
                    current = Directory.GetCurrentDirectory() + @"\新世代";
                    list = new List<string>(myPath.SetXinshidaiPath());
                    GetXml();
                    InfoText("********提取新世代核心文件********");
                    break;

                case 5:
                    current = Directory.GetCurrentDirectory() + @"\日月通用";
                    list = new List<string>(myPath.SetRiyuePath());
                    GetXml();
                    InfoText("********提取日月通用核心文件********");
                    break;
            }
            void GetXml()
            {
                if (XPath_textBox.Text == current) return;
                if (Directory.Exists(current)) Directory.Delete(current, true);
                Directory.CreateDirectory(current);
                list.AddRange(myPath.pathList);
                foreach (var item in list)
                {
                    string newfile = item.Replace(myPath.xPath, "");
                    if (!String.IsNullOrEmpty(newfile)) File.Copy(item, current + newfile);
                }
                MessageBox.Show("请在下个对话框选择 “确定” 更改文件地址,确保下次打开软件时可以自动读取提取出来的XML文件,如果XML文件有更新,请再从新提取最新文件");
                XPath_textBox.Text = current;
            }
        }

        /// <summary>
        /// 9.输出上次提取时间
        /// </summary>
        private void timebutton_Click(object sender, EventArgs e)
        {
            string current;
            switch (index)
            {
                case 0:
                    current = Directory.GetCurrentDirectory() + @"\日月\pets.xml";
                    GetTime("日月");
                    break;

                case 1:
                    current = Directory.GetCurrentDirectory() + @"\决斗\pets.xml";
                    GetTime("决斗");
                    break;

                case 2:
                    current = Directory.GetCurrentDirectory() + @"\新喵喵\pets.xml";
                    GetTime("新喵喵");
                    break;

                case 3:
                    current = Directory.GetCurrentDirectory() + @"\新逆袭\pets.xml";
                    GetTime("新逆袭");
                    break;

                case 4:
                    current = Directory.GetCurrentDirectory() + @"\新世代\pets.xml";
                    GetTime("新世代");
                    break;

                case 5:
                    current = Directory.GetCurrentDirectory() + @"\日月通用\pets.xml";
                    GetTime("日月通用");
                    break;
            }
            void GetTime(string name)
            {
                if (!File.Exists(current))
                {
                    InfoText("无提取时间记录");
                    return;
                }
                DateTime time = File.GetCreationTime(current);
                InfoText(name + " 最后提取时间为：" + time.ToString());
            }
        }

        /// <summary>
        /// 10.选择热更精灵数据文件
        /// </summary>
        private void XPath_button2_Click(object sender, EventArgs e)
        {
            if (DialogResult.OK == openFileDialog.ShowDialog())
            {
                XPath_textBox2.Text = openFileDialog.FileName;
                check_button2.Enabled = true;
            }
        }

        /// <summary>
        /// 11.执行精灵数据验证
        /// </summary>
        private void check_button2_Click(object sender, EventArgs e)
        {
            myPath.dataPath = XPath_textBox2.Text;
            if (myLoad.LoadData())
            {
                InfoText(myLoad.DataEqual());
                dataInfo_button.Enabled = true;
            }
            else
            {
                InfoText(myLoad.TempMessage);
                dataInfo_button.Enabled = true;
            }
        }

        /// <summary>
        /// 12.输入热更数据地址
        /// </summary>
        private void XPath_textBox2_TextChanged(object sender, EventArgs e)
        {
            string path = XPath_textBox2.Text;
            if (!String.IsNullOrEmpty(path))
            {
                if (File.Exists(path))
                {
                    check_button2.Enabled = true;
                }
                else
                {
                    check_button2.Enabled = false;
                    MessageBox.Show("路径无效", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
        }

        /// <summary>
        /// 13.展示数据验证详情
        /// </summary>
        private void dataInfo_button_Click(object sender, EventArgs e)
        {
            if (form2 != null)
            {
                form2.SetInfo(myLoad.dataInfo);
                form2.ShowDialog();
            }
            else
            {
                form2 = new Form2();
                form2.SetInfo(myLoad.dataInfo);
                form2.ShowDialog();
            }
            
        }

        /// <summary>
        /// 14.智能验证说明
        /// </summary>
        private void button1_Click(object sender, EventArgs e)
        {
            switch (index)
            {
                case 0:
                    MessageBox.Show("*日月*智能验证包含以下属性：\n闪光, 图鉴, 进化ID, 前置ID, 进化, 升星, 升阶, 进化石返还, Z技能, 专属技能, 专属特性, 传说任务, 究极属性");
                    break;
                case 1:
                    MessageBox.Show("*决斗*智能验证包含以下属性：\n进化ID, 是否无性别, 闪光, 图鉴, 升阶, 升星, 学习机, 成长技能, 普通特性, 性格洗练, Z技能, Mega等级强化ID");
                    break;
                case 2:
                    MessageBox.Show("*新喵喵*智能验证包含以下属性：\n进化ID, 是否无性别, 闪光, 图鉴, 升阶, 升星, 学习机, 成长技能, 普通特性, 性格洗练");
                    break;
                case 3:
                    MessageBox.Show("*新逆袭*智能验证包含以下属性：\n闪光, 学习机, 成长技能, 普通特性, Z技能, 升星, 升阶");
                    break;
                case 4:
                    MessageBox.Show("*新世代*智能验证包含以下属性：\n进化ID, 是否无性别, 闪光, 图鉴, 升阶, 升星, 学习机, 成长技能, 普通特性, 性格洗练, Z技能");
                    break;
                default:
                    MessageBox.Show("当前项目暂时不支持智能验证");
                    break;
            }
        }

        /// <summary>
        /// 清空提示内容
        /// </summary>
        private void Clearinfo_button_Click(object sender, EventArgs e)
        {
            info_richTextBox.Clear();
        }


        /// <summary>
        /// 清空表格内容
        /// </summary>
        private void ClearlistView_button_Click(object sender, EventArgs e)
        {
            this.X_listView.BeginUpdate();
            this.ab_listView.BeginUpdate();
            this.X_listView.Clear();
            this.ab_listView.Clear();
            this.X_listView.EndUpdate();
            this.ab_listView.EndUpdate();
        }

        /// <summary>
        /// 清空table2提示内容
        /// </summary>
        private void Clearinfo_button2_Click(object sender, EventArgs e)
        {
            info_richTextBox2.Clear();
        }

        /// <summary>
        /// 清空table2表格内容
        /// </summary>
        private void ClearlistView_button2_Click(object sender, EventArgs e)
        {
            table2_listView.BeginUpdate();
            table2_listView.Clear();
            table2_listView.EndUpdate();
        }

        /// <summary>
        /// 双击清空输入框中字体
        /// </summary>
        private void Name_textBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            Name_textBox.Clear();
        }

        /// <summary>
        /// 双击清空输入框中字体
        /// </summary>
        private void XmlName_textBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            XmlName_textBox.Clear();
        }

        /// <summary>
        /// 双击清空输入框中字体
        /// </summary>
        private void XmlIndex_textBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            XmlIndex_textBox.Clear();
        }

        /// <summary>
        /// 双击输出表格1内容
        /// </summary>
        private void X_listView_MouseDoubleClick_1(object sender, MouseEventArgs e)
        {
            PrintListinfo((ListView)sender);
        }

        /// <summary>
        /// 双击输出表格2内容
        /// </summary>
        private void table2_listView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            PrintListinfo((ListView)sender);
        }

        void PrintListinfo(ListView listView)
        {
            ListView.SelectedListViewItemCollection items = listView.SelectedItems;
            ListViewItem.ListViewSubItemCollection subitems = items[0].SubItems;
            StringBuilder builder = new StringBuilder();
            foreach (ListViewItem.ListViewSubItem item2 in subitems)
            {
                builder.Append(item2.Text + " ");
            }
            InfoText(builder.ToString());
        }

        /// <summary>
        /// 双击清空宝箱输入框文本
        /// </summary>
        private void chest_textBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            chest_textBox.Clear();
        }

        /// <summary>
        /// 选择 chest 查询类型
        /// </summary>
        private void chest_comboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!myLoad.LoadChest())
            {
                InfoText2(myLoad.TempMessage);
            }
            else
            {
                InfoText2("--宝箱数据导入完成--");
            }
        }

        /// <summary>                                
        /// 为表格添加指定类型数据
        /// </summary>
        void SetListViewItem(object Key)
        {
            //数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度
            this.X_listView.BeginUpdate();
            this.ab_listView.BeginUpdate();

            ListViewItem lvi = new ListViewItem();
            ListViewItem lvi2 = new ListViewItem();

            //将返回值拆箱
            SortedList<int, string> chineseList = GetShortName();

            //获取跳转字段
            HashK<string, string[]> jumpList = GetJumpList();

            if (this.X_listView.Columns.Count == 0)
            {
                foreach (var ch in chineseList.Values)
                {
                    if (ch == "精灵分解") this.X_listView.Columns.Add(ch, 400, HorizontalAlignment.Left);
                    else if (ch == "精灵名字") this.X_listView.Columns.Add(ch, 120, HorizontalAlignment.Left);
                    else if (ch == "特性列表") this.X_listView.Columns.Add(ch, 180, HorizontalAlignment.Left);
                    else if (ch == "升星材料") this.X_listView.Columns.Add(ch, 170, HorizontalAlignment.Left);
                    else if (ch == "进化材料") this.X_listView.Columns.Add(ch, 200, HorizontalAlignment.Left);
                    else if (ch == "返还材料") this.X_listView.Columns.Add(ch, 105, HorizontalAlignment.Left);
                    else if (ch == "返还精灵数") this.X_listView.Columns.Add(ch, 180, HorizontalAlignment.Left);
                    else if (ch == "Z技能") this.X_listView.Columns.Add(ch, 100, HorizontalAlignment.Left);
                    else if (ch == "z技能Buff") this.X_listView.Columns.Add(ch, 200, HorizontalAlignment.Left);
                    else if (ch == "专属技能") this.X_listView.Columns.Add(ch, 100, HorizontalAlignment.Left);
                    else if (ch == "转生属性") this.X_listView.Columns.Add(ch, 250, HorizontalAlignment.Left);
                    else this.X_listView.Columns.Add(ch, 78, HorizontalAlignment.Left);
                }
                this.X_listView.Columns.Add("End", 50, HorizontalAlignment.Left);
            }

            if (this.ab_listView.Columns.Count == 0)
            {
                string[] handle = { "精灵名称", "模型", "系列", "属性1", "属性2", "稀有", "血量", "物攻", "物防", "特攻", "特防", "速度", "种族值", "性别", "无性", "闪光", "图鉴", "End" };
                string[] handle2 = { "精灵名称", "模型", "精灵名字_避版", "模型_避版", "系列", "属性1", "属性2", "稀有", "血量", "物攻", "物防", "特攻", "特防", "速度", "种族值", "性别", "无性", "闪光", "图鉴", "End" };

                if (index == 0 || index == 1)
                {
                    foreach (var item in handle2)
                    {
                        if (item == "精灵名称") this.ab_listView.Columns.Add(item, 100, HorizontalAlignment.Left);
                        else if (item == "模型") this.ab_listView.Columns.Add(item, 200, HorizontalAlignment.Left);
                        else if (item == "精灵名字_避版") this.ab_listView.Columns.Add(item, 100, HorizontalAlignment.Left);
                        else if (item == "模型_避版") this.ab_listView.Columns.Add(item, 200, HorizontalAlignment.Left);
                        else this.ab_listView.Columns.Add(item, 50, HorizontalAlignment.Left);
                    }
                }
                else if (index == 3)
                {
                    foreach (var item in handle)
                    {
                        if (item == "精灵名称") this.ab_listView.Columns.Add(item, 100, HorizontalAlignment.Left);
                        else if (item == "模型") this.ab_listView.Columns.Add(item, 200, HorizontalAlignment.Left);
                        else if (item != "系列") this.ab_listView.Columns.Add(item, 50, HorizontalAlignment.Left);
                    }
                }
                else
                {
                    foreach (var item in handle)
                    {
                        if (item == "精灵名称") this.ab_listView.Columns.Add(item, 100, HorizontalAlignment.Left);
                        else if (item == "模型") this.ab_listView.Columns.Add(item, 200, HorizontalAlignment.Left);
                        else this.ab_listView.Columns.Add(item, 50, HorizontalAlignment.Left);
                    }
                }
            }

            string zero = "0";
            string exception = "*异常*";
            string strTemp;
            foreach (FieldInfo item in myLoad.petTypeDic.Values)
            {
                void TryCatch1(string value)
                {
                    try
                    {
                        lvi.SubItems.Add(jumpList.GetTvalue(item.Name)[Int32.Parse(value)]);
                    }
                    catch (Exception)
                    {
                        lvi.SubItems.Add(exception);
                    }
                }

                void TryCatch2(string value)
                {
                    try
                    {
                        lvi2.SubItems.Add(jumpList.GetTvalue(item.Name)[Int32.Parse(value)]);
                    }
                    catch (Exception)
                    {
                        lvi2.SubItems.Add(exception);
                    }
                }

                //获取对应字段的 实例
                string itemValue = "";
                if (item.Name != "pokeCharacterClearId")
                {
                    //获取 指定类型对象 的对应字段的值
                    if (item.GetValue(Key) == null) itemValue = "";
                    else itemValue = item.GetValue(Key).ToString();
                }

                switch (item.Name)
                {
                    case "petId": //精灵ID
                        lvi.Text = itemValue;
                        break;

                    case "petName": //精灵名字
                        lvi.SubItems.Add(itemValue);
                        lvi2.Text = itemValue;
                        break;

                    case "petModel": //模型
                        lvi2.SubItems.Add(itemValue);
                        break;

                    case "petName_bak": //精灵名字_避版
                        lvi2.SubItems.Add(itemValue);
                        break;

                    case "petModel_bak": //模型_避版
                        lvi2.SubItems.Add(itemValue);
                        break;

                    case "nextPetId": //进化Id
                        if (myLoad.petNameHK.ContainsValue(itemValue)) lvi.SubItems.Add(myLoad.petNameHK.GetTkey(itemValue));
                        else if (itemValue == zero) lvi.SubItems.Add(zero);
                        else lvi.SubItems.Add(exception);
                        break;

                    case "prePetId": //前置Id
                        if (myLoad.petNameHK.ContainsValue(itemValue)) lvi.SubItems.Add(myLoad.petNameHK.GetTkey(itemValue));
                        else if (itemValue == zero) lvi.SubItems.Add(zero);
                        else lvi.SubItems.Add(exception);
                        break;

                    case "serise": //系列ID
                        lvi2.SubItems.Add(itemValue);
                        break;

                    case "element1": //属性1
                        try
                        {
                            int element1index = Int32.Parse(itemValue);
                            if (element1index < 0) lvi2.SubItems.Add("无");
                            else lvi2.SubItems.Add(itemValue + "(" + jumpList.GetTvalue(item.Name)[element1index] + ")");
                        }
                        catch (Exception)
                        {
                            lvi2.SubItems.Add(exception);
                        }
                        break;

                    case "element2": //属性2
                        try
                        {
                            int element2index = Int32.Parse(itemValue);
                            if (element2index < 0) lvi2.SubItems.Add("无");
                            else lvi2.SubItems.Add(itemValue + "(" + jumpList.GetTvalue(item.Name)[element2index] + ")");
                        }
                        catch (Exception)
                        {
                            lvi2.SubItems.Add(exception);
                        }
                        break;

                    case "petRank": //新逆袭稀有度
                        if (index == 3)
                        {
                            TryCatch2(itemValue);
                        }
                        break;

                    case "petRankShow": //稀有度
                        TryCatch2(itemValue);
                        break;

                    case "petAbilityId": //种族值
                        Ability ability = myLoad.abilityHK.GetTvalue(itemValue);
                        try
                        {
                            lvi2.SubItems.Add(ability.hp);
                            lvi2.SubItems.Add(ability.physicalDamage);
                            lvi2.SubItems.Add(ability.physicalDefence);
                            lvi2.SubItems.Add(ability.specialDamage);
                            lvi2.SubItems.Add(ability.specialDefence);
                            lvi2.SubItems.Add(ability.speed);
                            int count = Int32.Parse(ability.hp) + Int32.Parse(ability.physicalDamage) + Int32.Parse(ability.physicalDefence)
                                + Int32.Parse(ability.specialDamage) + Int32.Parse(ability.specialDefence) + Int32.Parse(ability.speed);
                            lvi2.SubItems.Add(count.ToString());
                        }
                        catch (Exception)
                        {
                            lvi2.SubItems.Add(exception);
                        }
                        break;

                    case "sex": //性别
                        TryCatch2(itemValue);
                        break;

                    case "isNullSex": //无性别
                        switch (itemValue)
                        {
                            case "false":
                                itemValue = zero;
                                break;

                            case "true":
                                itemValue = "1";
                                break;
                        }
                        TryCatch2(itemValue);
                        break;

                    case "flash": //是否闪光
                        TryCatch2(itemValue);
                        break;

                    case "isInPokeindex": //图鉴展示
                        TryCatch2(itemValue);
                        break;

                    case "growSkill": //成长技能
                        if (myLoad.gskillHK.GetTvalue(itemValue)) lvi.SubItems.Add("技能正常");
                        else lvi.SubItems.Add(exception);
                        break;

                    case "studySkill": //学习技能
                        if (myLoad.sskillHK.GetTvalue(itemValue)) lvi.SubItems.Add("技能正常");
                        else lvi.SubItems.Add(exception);
                        break;

                    case "characteristic": //普通特性
                        lvi.SubItems.Add(itemValue);
                        if (myLoad.pmCharacteristicHK.ContainsKey(itemValue))
                        {
                            HashSet<string> set = myLoad.pmCharacteristicHK.GetTvalue(itemValue);
                            StringBuilder builder = new StringBuilder();
                            foreach (var Characteristic in set)
                            {
                                if (myLoad.pmAbilityHK.ContainsKey(Characteristic))
                                {
                                    builder.Append(myLoad.pmAbilityHK.GetTvalue(Characteristic) + " ");
                                }
                                else
                                {
                                    builder.Append(Characteristic + " ");
                                }
                            }
                            
                            lvi.SubItems.Add(builder.ToString());
                        }
                        else lvi.SubItems.Add(exception);
                        break;

                    case "petUpgradeCondition": //升阶所需条件
                        lvi.SubItems.Add(itemValue);
                        break;

                    case "petStarIncreaseCondition": 
                        StringBuilder builder1 = new StringBuilder();
                        if (index == 0 || index == 3 || index == 5) //日月/新逆袭 升星
                        {
                            lvi.SubItems.Add(itemValue);
                            if (myLoad.starCondition035HK.ContainsKey(itemValue))
                            {
                                StarCondition035 starCondition = myLoad.starCondition035HK.GetTvalue(itemValue);
                                List<string> itemLists = new List<string>(6);
                                itemLists.Add(starCondition.levelItemListId1);
                                itemLists.Add(starCondition.levelItemListId2);
                                itemLists.Add(starCondition.levelItemListId3);
                                itemLists.Add(starCondition.levelItemListId4);
                                itemLists.Add(starCondition.levelItemListId5);
                                itemLists.Add(starCondition.levelItemListId6);
                                if (index == 3)
                                {
                                    itemLists.Add(starCondition.levelItemListId7);
                                    itemLists.Add(starCondition.levelItemListId8);
                                    itemLists.Add(starCondition.levelItemListId9);
                                    itemLists.Add(starCondition.levelItemListId10);
                                    itemLists.Add(starCondition.levelItemListId11);
                                    itemLists.Add(starCondition.levelItemListId12);
                                }
                                itemLists.TrimExcess();
                                foreach (var itemtemp in itemLists)
                                {
                                    if (!string.IsNullOrEmpty(itemtemp))
                                    {
                                        if (myLoad.starItemListHK.ContainsKey(itemtemp))
                                        {
                                            StarItemList itemList = myLoad.starItemListHK.GetTvalue(itemtemp);

                                            if (itemList.item1_id == zero) builder1.Append(itemList.item1_id + " ");
                                            else builder1.Append(myLoad.itemsHK.GetTvalue(itemList.item1_id) + "[" + itemList.item1_num + "] ");

                                            if (itemList.item2_id == zero) builder1.Append(itemList.item2_id + ", ");
                                            else builder1.Append(myLoad.itemsHK.GetTvalue(itemList.item2_id) + "[" + itemList.item2_num + "], ");
                                        }
                                        else if (itemtemp != zero)
                                        {
                                            builder1.Append("** " + itemtemp + " 异常**,");
                                        }
                                    }
                                }
                                lvi.SubItems.Add(builder1.ToString());
                            }
                            else lvi.SubItems.Add(exception);
                        }
                        else if (index == 1 || index == 2 || index == 4) //决斗/新喵喵/新世代 升星
                        {
                            lvi.SubItems.Add(itemValue);

                            if (myLoad.starCondition124HK.ContainsKey(itemValue))
                            {
                                StarCondition124 starContentIds = myLoad.starCondition124HK.GetTvalue(itemValue);
                                Type starCondition = typeof(StarCondition124);
                                FieldInfo[] fieldInfoArray = starCondition.GetFields();
                                int length = fieldInfoArray.Length-1;

                                if (index == 4) length++;

                                for (int i = 0; i < length; i++)
                                {
                                    string key = fieldInfoArray[i].GetValue(starContentIds).ToString();
                                    if (i != 8)
                                    {
                                        if (myLoad.starContent124HK.ContainsKey(key))
                                        {
                                            StarContent starLevelCostId = myLoad.starContent124HK.GetTvalue(key);
                                            string levelCostId_1 = starLevelCostId.levelCostId_1;
                                            if (myLoad.starLevelCost124HK.ContainsKey(levelCostId_1))
                                            {
                                                StarLevelCost starLevelCost = myLoad.starLevelCost124HK.GetTvalue(levelCostId_1);
                                                builder1.Append(string.Format("【{0} {1}】", myLoad.itemsHK.GetTvalue(starLevelCost.item_2), myLoad.itemsHK.GetTvalue(starLevelCost.item_3)));
                                            }
                                            else builder1.Append(exception + "2");
                                        }
                                        else builder1.Append(exception + "1");
                                    }
                                    else
                                    {
                                        builder1.Append(" 转：" + key);
                                    }
                                }

                                lvi.SubItems.Add(builder1.ToString());
                            }
                            else lvi.SubItems.Add(exception+"0");
                        }
                        else lvi.SubItems.Add(itemValue);
                        break;

                    case "evolutionCondition": //进化所需条件
                        if (itemValue == zero)
                        {
                            lvi.SubItems.Add(itemValue);
                            lvi.SubItems.Add(itemValue);
                        }
                        else
                        {
                            string[] temp = itemValue.Split(';');
                            StringBuilder evolutionConditionbuilder = new StringBuilder();
                            for (int x = 0; x < temp.Length; x++)
                            {
                                if (myLoad.evolutionConditionHK.ContainsKey(temp[x]))
                                {
                                    strTemp = myLoad.evolutionConditionHK.GetTvalue(temp[x]);
                                    string[] str2 = strTemp.Split(';');
                                    for (int i = 1; i < str2.Length; i++)
                                    {
                                        string[] str3 = str2[i].Split(',');
                                        if (myLoad.itemsHK.ContainsKey(str3[0])) evolutionConditionbuilder.Append(myLoad.itemsHK.GetTvalue(str3[0]) + "[" + str3[1] + "]" + ", ");
                                        else evolutionConditionbuilder.Append(zero + ", ");
                                    }
                                }
                                else evolutionConditionbuilder.Append(exception);
                            }
                            lvi.SubItems.Add(itemValue);
                            lvi.SubItems.Add(evolutionConditionbuilder.ToString());
                        }
                        break;
                }

                if (index == 0 || index == 5) //日月&日月通用
                {
                    switch (item.Name)
                    {
                        case "resetEvolution": //日月 进化石返还
                            if (itemValue != zero & itemValue != "" & myLoad.resetEvolutionListHK.ContainsKey(itemValue))
                            {
                                lvi.SubItems.Add(itemValue); //进化石返还ID

                                string awakenItemId;
                                ResetEvolutionList reset = myLoad.resetEvolutionListHK.GetTvalue(itemValue);

                                if (reset.awakenItemId_1 == zero) awakenItemId = "【0】";
                                else awakenItemId = "【" + myLoad.itemsHK.GetTvalue(reset.awakenItemId_1) + "[" + reset.awakenItemNumber_1 + "]】 ";

                                if (reset.awakenItemId_2 == zero) awakenItemId += "【0】";
                                else awakenItemId += "【" + myLoad.itemsHK.GetTvalue(reset.awakenItemId_2) + "[" + reset.awakenItemNumber_2 + "]】 ";

                                if (reset.awakenLv == zero) awakenItemId += "（0）";
                                else awakenItemId += "(" + reset.awakenLv + ")";

                                lvi.SubItems.Add(awakenItemId);//返还材料和数量

                                if (reset.resetPokeNumber == zero) lvi.SubItems.Add(zero);//返还精灵数
                                else lvi.SubItems.Add(reset.resetPokeNumber);
                            }
                            else
                            {
                                lvi.SubItems.Add(zero);
                                lvi.SubItems.Add(zero);
                                lvi.SubItems.Add(zero);
                            }
                            break;

                        case "zMove": //Z技能
                            if (myLoad.pmMoveHK.ContainsKey(itemValue)) lvi.SubItems.Add(myLoad.pmMoveHK.GetTvalue(itemValue).pmAcitveMoveName);
                            else lvi.SubItems.Add(zero);
                            break;

                        case "zMoveBuff": //Z技能Buff
                            lvi.SubItems.Add(itemValue);
                            break;

                        case "exclusiveSkill": //日月专属技能
                            if (myLoad.pmMoveHK.ContainsKey(itemValue)) lvi.SubItems.Add(myLoad.pmMoveHK.GetTvalue(itemValue).pmAcitveMoveName);
                            else lvi.SubItems.Add(zero);
                            break;

                        case "exclusiveAbility": //日月专属特性
                            if (myLoad.pmAbilityHK.ContainsKey(itemValue)) lvi.SubItems.Add(myLoad.pmAbilityHK.GetTvalue(itemValue));
                            else lvi.SubItems.Add(zero);
                            break;

                        case "isNotMelt": //是否究极
                            TryCatch1(itemValue);
                            break;

                        case "elementListId": //究极属性
                            if (!String.IsNullOrEmpty(itemValue)) lvi.SubItems.Add(itemValue);
                            else lvi.SubItems.Add(zero);
                            break;

                        case "legendQuestListId": //传说任务
                            lvi.SubItems.Add(itemValue);
                            break;

                        case "isInMega3Index": //融合表展示
                            TryCatch1(itemValue);
                            break;
                    }
                }

                if (index == 1) //决斗
                {
                    switch (item.Name)
                    {
                        case "zMove": //Z技能
                            if (myLoad.pmMoveHK.ContainsKey(itemValue)) lvi.SubItems.Add(myLoad.pmMoveHK.GetTvalue(itemValue).pmAcitveMoveName);
                            else lvi.SubItems.Add(zero);
                            break;

                        case "zMoveBuff": //Z技能Buff
                            lvi.SubItems.Add(itemValue);
                            break;

                        case "pokeCharacterClearId": //性格洗练ID

                            switch (myLoad.pokeCharacterClearHK.GetTvalue(lvi.Text))
                            {
                                case "170200001":
                                    lvi.SubItems.Add("稀有洗练");
                                    break;

                                case "170200002":
                                    lvi.SubItems.Add("史诗洗练");
                                    break;

                                case "170200003":
                                    lvi.SubItems.Add("传说洗练");
                                    break;

                                case "170200004":
                                    lvi.SubItems.Add("至尊洗练");
                                    break;

                                default:
                                    lvi.SubItems.Add(zero);
                                    break;
                            }
                            break;
                        case "megaStrengthenId": //M11特性
                            if (myLoad.megaLvSysHK.ContainsKey(itemValue)) lvi.SubItems.Add(myLoad.pmAbilityHK.GetTvalue(myLoad.megaLvSysHK.GetTvalue(itemValue)));
                            else lvi.SubItems.Add(zero);
                            break;

                        case "disintegrate": //精灵分解
                            if (myLoad.disintegrateHK.ContainsKey(lvi.Text))
                            {
                                Disintegrate disintegrate = myLoad.disintegrateHK.GetTvalue(lvi.Text);
                                Type type = typeof(Disintegrate);
                                FieldInfo[] fieldInfo = type.GetFields();
                                StringBuilder builder3 = new StringBuilder();
                                foreach (FieldInfo info in fieldInfo)
                                {
                                    string str = info.GetValue(disintegrate).ToString();
                                    if (str != "0" & str != "0,0")
                                    {
                                        if (!str.Contains(","))
                                        {
                                            if (myLoad.itemsHK.ContainsKey(str)) builder3.Append(myLoad.itemsHK[str].ToString());
                                            else builder3.Append(exception);
                                        }
                                        else builder3.Append(",(" + str + ") ");
                                    }

                                }
                                lvi.SubItems.Add(builder3.ToString());
                            }
                            else lvi.SubItems.Add(zero);
                            break;
                    }
                }

                if (index == 2) //新喵喵
                {
                    switch (item.Name)
                    {
                        case "dynamaxPetId": //极巨化精灵
                            if (myLoad.petNameHK.ContainsValue(itemValue)) lvi.SubItems.Add(myLoad.petNameHK.GetTkey(itemValue));
                            else if (itemValue == zero) lvi.SubItems.Add(zero);
                            else lvi.SubItems.Add(exception);
                            break;

                        case "wristbandLvId": //极巨腕带
                            lvi.SubItems.Add(itemValue);
                            break;

                        case "pokeCharacterClearId": //性格洗练ID

                            switch (myLoad.pokeCharacterClearHK.GetTvalue(lvi.Text))
                            {
                                case "170200001":
                                    lvi.SubItems.Add("稀有洗练");
                                    break;

                                case "170200002":
                                    lvi.SubItems.Add("史诗洗练");
                                    break;

                                case "170200003":
                                    lvi.SubItems.Add("传说洗练");
                                    break;

                                case "170200004":
                                    lvi.SubItems.Add("至尊洗练");
                                    break;

                                default:
                                    lvi.SubItems.Add(zero);
                                    break;
                            }
                            break;

                        case "disintegrate": //精灵分解
                            if (myLoad.disintegrateHK.ContainsKey(lvi.Text))
                            {
                                Disintegrate disintegrate = myLoad.disintegrateHK.GetTvalue(lvi.Text);
                                Type type = typeof(Disintegrate);
                                FieldInfo[] fieldInfo = type.GetFields();
                                StringBuilder builder3 = new StringBuilder();
                                foreach (FieldInfo info in fieldInfo)
                                {
                                    object obj = info.GetValue(disintegrate);
                                    string str = obj.ToString();
                                    if (str != "0" & str != "0,0")
                                    {
                                        if (!str.Contains(","))
                                        {
                                            if (myLoad.itemsHK.ContainsKey(str)) builder3.Append(myLoad.itemsHK[str].ToString());
                                            else builder3.Append(exception);
                                        }
                                        else builder3.Append(",(" + str + ") ");
                                    }
                                }
                                lvi.SubItems.Add(builder3.ToString());
                            }
                            else lvi.SubItems.Add(zero);
                            break;
                    }
                }

                if (index == 3) //新逆袭
                {
                    switch (item.Name)
                    {
                        case "MegaPetId": //超进化ID
                            if (myLoad.petNameHK.ContainsValue(itemValue)) lvi.SubItems.Add(myLoad.petNameHK.GetTkey(itemValue));
                            else if (itemValue == zero) lvi.SubItems.Add(zero);
                            else lvi.SubItems.Add(exception);
                            break;

                        case "zMove": //Z技能
                            if (myLoad.pmMoveHK.ContainsKey(itemValue)) lvi.SubItems.Add(myLoad.pmMoveHK.GetTvalue(itemValue).pmAcitveMoveName);
                            else lvi.SubItems.Add(zero);
                            break;

                        case "zMoveBuff": //Z技能Buff
                            lvi.SubItems.Add(itemValue);
                            break;

                        case "ReleaseDropId": //放生掉落
                            if (myLoad.dropHK.ContainsKey(itemValue)) lvi.SubItems.Add(myLoad.dropHK.GetTvalue(itemValue));
                            else lvi.SubItems.Add(zero);
                            break;
                    }
                }

                if (index == 4) //新世代
                {
                    switch (item.Name)
                    {
                        case "isNotMelt": //是否究极
                            TryCatch1(itemValue);
                            break;

                        case "isAwakenAgain": //是否转生精灵
                            TryCatch1(itemValue);
                            break;

                        case "ReleaseDropId": //放生掉落
                            if (myLoad.dropHK.ContainsKey(itemValue)) lvi.SubItems.Add(myLoad.itemsHK.GetTvalue(myLoad.dropHK.GetTvalue(itemValue)));
                            else lvi.SubItems.Add(exception);
                            break;

                        case "awakenAgainCondition": //转生条件
                            lvi.SubItems.Add(itemValue);
                            break;

                        case "zMove": //Z技能
                            if (myLoad.pmMoveHK.ContainsKey(itemValue)) lvi.SubItems.Add(myLoad.pmMoveHK.GetTvalue(itemValue).pmAcitveMoveName);
                            else lvi.SubItems.Add(zero);
                            break;

                        case "zMoveBuff": //Z技能Buff
                            lvi.SubItems.Add(itemValue);
                            break;

                        case "petAwakenAgainAbilityId": //转生属性
                            if (myLoad.abilityHK.ContainsKey(itemValue))
                            {
                                Ability ability = myLoad.abilityHK.GetTvalue(itemValue);
                                lvi.SubItems.Add("血" + ability.hp + ", 物" + ability.physicalDamage + ", 防" + ability.physicalDefence + ", 特" + ability.specialDamage + ", 抗" + ability.specialDefence + ", 速" + ability.speed);
                            }
                            else lvi.SubItems.Add(exception);
                            break;
                    }
                }
            }

            //为数据列表添加一行数据
            this.X_listView.Items.Add(lvi);
            this.ab_listView.Items.Add(lvi2);

            //结束数据处理,UI界面一次性绘制
            this.X_listView.EndUpdate();
            this.ab_listView.EndUpdate();
        }

        /// <summary>
        /// 为table2表格添加指定数据
        /// </summary>
        void ShowListView(Chest chest)
        {
            ListViewItem lvi = new ListViewItem();
            Type type = typeof(Chest);
            FieldInfo[] fileInfo = type.GetFields();
            if (this.table2_listView.Columns.Count == 0)
            {
                for (int i = 0; i < fileInfo.Length; i++)
                {
                    if (fileInfo[i].Name == "items")
                    {
                        this.table2_listView.Columns.Add(fileInfo[i].Name, 3000, HorizontalAlignment.Left);
                    }
                    else
                    {
                        this.table2_listView.Columns.Add(fileInfo[i].Name, 70, HorizontalAlignment.Left);
                    }
                }
                this.table2_listView.Columns.Add("End", 50, HorizontalAlignment.Left);
            }
            lvi.Text = chest.chestId;
            lvi.SubItems.Add(chest.chestName);
            lvi.SubItems.Add(chest.chestQuality);
            lvi.SubItems.Add(chest.chestType);
            lvi.SubItems.Add(chest.randomNumList2Id);
            lvi.SubItems.Add(chest.items);
            this.table2_listView.Items.Add(lvi);
        }

        /// <summary>
        /// 输出文本信息
        /// </summary>
        void InfoText(string info)
        {
            info = info + "\n";
            info_richTextBox.AppendText(info);
        }

        /// <summary>
        /// 输出文本信息
        /// </summary>
        void InfoText2(string info)
        {
            info = info + "\n";
            info_richTextBox2.AppendText(info);
        }


        /// <summary>
        /// 修改地址库文件地址
        /// </summary>
        void ChangePath()
        {
            try
            {
                xmlDoc = new XmlDocument();
                xmlDoc.Load(oldPath);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }
            
            XmlElement root = xmlDoc.DocumentElement;
            XmlNodeList nodeList = root.ChildNodes;
            foreach (XmlNode item in nodeList)
            {
                string id = item.Attributes["ID"].Value;
                if (id == index.ToString())
                {
                    string temp = item.ChildNodes.Item(0).InnerText;
                    if (temp != myPath.xPath)
                    {
                        DialogResult result = MessageBox.Show("地址变更,是否保存新地址？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                        if (result == DialogResult.OK)
                        {
                            item.ChildNodes.Item(0).InnerText = myPath.xPath;
                            InfoText(id + " 新增地址：" + myPath.xPath);
                        }
                    }
                }
            }
            xmlDoc.Save(oldPath);
        }

        /// <summary>
        /// 字段跳转
        /// </summary>
        /// <returns></returns>
        HashK<string, string[]> GetJumpList()
        {
            HashK<string, string[]> sl = new HashK<string, string[]>();
            string[] 属性 = { "般", "格", "飞", "毒", "地", "岩", "虫", "幽", "钢", "炎", "水", "草", "电", "超", "冰", "龙", "恶", "妖" };
            string[] 是否 = { "否", "是" };
            string[] 无性别 = { "有性", "无性" };
            string[] 性别 = { "随机", "男", "女" };
            string[] 展示 = { "不展", "展示" };
            string[] 珍稀度 = default;
            switch (index)
            {
                case 0: //日月
                    珍稀度 = new string[] { "常见", "普通", "稀有", "史诗", "传说", "至尊" }; //5
                    break;

                case 1: //决斗
                    珍稀度 = new string[] { "无", "常见", "普通", "稀有", "史诗", "传说", "至尊" };  //6
                    break;

                case 2: //新喵喵
                    珍稀度 = new string[] { "无", "常见", "普通", "稀有", "史诗", "传说", "至尊" }; //6
                    break;

                case 3: //新逆袭
                    珍稀度 = new string[] { "无", "常见", "普通", "稀有", "史诗", "传说" }; //5
                    break;

                case 4: //新世代
                    珍稀度 = new string[] { "常见", "普通", "稀有", "史诗", "传说", "至尊" }; //5
                    break;

                case 5: //通用
                    珍稀度 = new string[] { "常见", "普通", "稀有", "史诗", "传说", "至尊" }; //5
                    break;
            }

            sl.Add("petRankShow", 珍稀度);
            sl.Add("petRank", 珍稀度);
            sl.Add("element1", 属性);
            sl.Add("element2", 属性);
            sl.Add("sex", 性别);
            sl.Add("isNullSex", 无性别);
            sl.Add("isInPokeindex", 是否);
            sl.Add("flash", 是否);
            sl.Add("isNotMelt", 是否);
            sl.Add("isInMega3Index", 展示);
            sl.Add("isAwakenAgain", 是否);

            return sl;
        }


        /// <summary>
        /// 项目查询控件开关, i = 0(全关),1(全开),2(关前两),3(开前两)
        /// </summary>
        void Step1(int i)
        {
            switch (i)
            {
                case 0: //全关
                    XPath_textBox.ReadOnly = true;
                    XPath_button.Enabled = false;
                    check_button.Enabled = false;
                    break;

                case 1: //全开
                    XPath_textBox.ReadOnly = false;
                    XPath_button.Enabled = true;
                    check_button.Enabled = true;
                    break;

                case 2: //关前两个
                    XPath_textBox.ReadOnly = true;
                    XPath_button.Enabled = false;
                    break;

                case 3: //开前两个
                    XPath_textBox.ReadOnly = false;
                    XPath_button.Enabled = true;
                    break;

                default:
                    break;
            }
        }

        /// <summary>
        /// 热更验证控件开关, i = 0(全关),1(全开),2(关前两),3(开前两)
        /// </summary>
        void Step2(int i)
        {
            switch (i)
            {
                case 0: //全关
                    XPath_textBox2.ReadOnly = true;
                    XPath_button2.Enabled = false;
                    check_button2.Enabled = false;
                    dataInfo_button.Enabled = false;
                    break;

                case 1: //全开
                    XPath_textBox2.ReadOnly = false;
                    XPath_button2.Enabled = true;
                    check_button2.Enabled = true;
                    dataInfo_button.Enabled = true;
                    break;

                case 2: //关前两个
                    XPath_textBox2.ReadOnly = true;
                    XPath_button2.Enabled = false;
                    break;

                case 3: //开前两个
                    XPath_textBox2.ReadOnly = false;
                    XPath_button2.Enabled = true;
                    break;

                default:
                    break;
            }
        }

        /// <summary>
        /// Table1控件开关, i = 0(全关),1(全开)
        /// </summary>
        /// <param name="i">0(全关),1(全开)</param>
        void Step3(int i)
        {
            if (i == 0)
            {
                timebutton.Enabled = false;
                getxml_button.Enabled = false;
            }
            else
            {
                timebutton.Enabled = true;
                getxml_button.Enabled = true;
            }
        }

        /// <summary>
        /// Table2控件开关, i = 0(全关),1(全开)
        /// </summary>
        /// <param name="i">0(全关),1(全开)</param>
        void Step4(int i)
        {
            if (i == 0)
            {
                dropLevel_button.Enabled = false;
                XmlXCheck_button.Enabled = false;
                chest_button.Enabled = false;
                chest_comboBox.Enabled = false;
            }
            else
            {
                dropLevel_button.Enabled = true;
                XmlXCheck_button.Enabled = true;
                chest_button.Enabled = true;
                chest_comboBox.Enabled = true;
            }
        }

        

        /// <summary>
        /// 获取数据列表表头
        /// </summary>
        /// <returns></returns>
        public SortedList<int, string> GetShortName()
        {
            List<string> name = default;
            switch (index)
            {
                case 1:
                    name = new List<string>(new string[] {
                        "精灵Id", "精灵名字", "进化Id", "前置Id", "成长技能", "学习技能", "普通特性", "特性列表" ,
                        "升阶条件" , "升星条件" ,"升星材料","进化条件","进化材料","Z技能","z技能Buff","性格洗练",
                        "Mega特性","精灵分解"});
                    break;
                case 2:
                    name = new List<string>(new string[] {
                        "精灵Id", "精灵名字", "进化Id", "前置ID","成长技能", "学习机", "普通特性", "特性列表", "升阶条件",
                        "升星条件", "升星材料", "进化条件", "进化材料","极巨精灵", "腕带ID" , "性格洗练" ,"精灵分解"});
                    break;
                case 3:
                    name = new List<string>(new string[] {
                        "精灵Id", "精灵名字","进化Id", "成长技能", "学习机", "普通特性", "特性列表", "升阶条件",
                        "升星条件","升星材料","进化条件", "进化材料" , "超进化id" , "z招式" ,"z技能Buff","放生掉落" });
                    break;
                case 4:
                    name = new List<string>(new string[] {
                        "精灵Id", "精灵名字", "进化Id", "前置Id", "成长技能", "学习技能", "普通特性", "特性列表" ,
                        "升阶条件" , "升星条件" ,"升星材料","进化条件","进化材料", "放生掉落","Z技能","z技能Buff",
                        "是否究极", "转生条件", "是否转生", "转生属性"});
                    break;
                default:
                    name = new List<string>(new string[] {
                        "精灵Id", "精灵名字","进化Id", "前置Id", "成长技能", "学习技能", "普通特性", "特性列表" ,  "升阶条件" ,
                        "升星条件" ,"升星材料","进化条件","进化材料", "进化石返还", "返还材料", "返还精灵数","Z技能", "z技能Buff",
                        "专属技能", "专属特性", "是否究极", "究极属性", "传说任务", "融合表展示" });
                    break;
            }

            SortedList<int, string> sl = new SortedList<int, string>();
            for (int i = 0; i < name.Count; i++)
            {
                sl.Add(i, name[i]);
            }
            sl.TrimExcess();
            return sl;
        }

        private void showButton_Click(object sender, EventArgs e)
        {
            messageBox.Clear();
            messageBox.AppendText(PrintMessage.Message_now);
        }
    }   
}
